package com.example.tms.mapper;

import com.example.tms.bean.DriverInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 司机信息
 */
@Repository
public interface DriverMapper extends JpaRepository<DriverInfo, String>, JpaSpecificationExecutor<DriverInfo>{

    //查询司机信息（司机id）
    @Query(value = "select * from driver_info where sjid = ?1 and sfcz = true ", nativeQuery = true)
    DriverInfo findBySjid(String sjid);

    //删除司机信息（假删除 司机id）
    @Query(value = "update driver_info set sfcz = false where sjid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void deleteBySjid(String sjid);

    //查询司机信息（驾驶员手机）
    DriverInfo findByJsysjAndSfcz(String jsysjh, boolean sfcz);

    //查询司机信息（身份证号）
    DriverInfo findBySfzhAndSfcz(String sfzh, boolean sfcz);

    //查询司机信息（司机姓名）
    DriverInfo findByJsyxm(String jsyxm);
}
